package main

import "fmt"

// Person 声明一个新的类型
type Person struct {
	name string
	age  int
}

// Older 比较两个人的年龄，返回年龄大的那个人，并且返回年龄差
// struct也是传值的
func Older(p1, p2 Person) (Person, int) {
	if p1.age > p2.age { // 比较p1和p2这两个人的年龄
		return p1, p1.age - p2.age
	}
	return p2, p2.age - p1.age
}

// main
func main() {
	var tom Person

	// 赋值初始化
	tom.name, tom.age = "Tom", 18

	// 两个字段都写清楚的初始化
	bob := Person{age: 25, name: "Bob"}

	// 按照struct定义顺序初始化值
	paul := Person{"Paul", 43}

	tbOlder, tbDiff := Older(tom, bob)
	tpOlder, tpDiff := Older(tom, paul)
	bpOlder, bpDiff := Older(bob, paul)

	fmt.Printf("Of %s and %s, %s is older by %d years\n",
		tom.name, bob.name, tbOlder.name, tbDiff)

	fmt.Printf("Of %s and %s, %s is older by %d years\n",
		tom.name, paul.name, tpOlder.name, tpDiff)

	fmt.Printf("Of %s and %s, %s is older by %d years\n",
		bob.name, paul.name, bpOlder.name, bpDiff)
}
